package com.chcit.mobile.mvp.model;

import android.app.Application;

import com.alibaba.fastjson.JSONObject;
import com.chcit.mobile.mvp.model.api.service.UserService;
import com.chcit.mobile.mvp.model.entity.InventoryPlanBean;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.FragmentScope;

import javax.inject.Inject;

import com.chcit.mobile.mvp.contract.InventoryPlanQueryContract;

import java.util.List;

import io.reactivex.Observable;


@FragmentScope
public class InventoryPlanQueryModel extends BaseModel implements InventoryPlanQueryContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public InventoryPlanQueryModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<List<InventoryPlanBean>> getData(JSONObject json) {
        return mRepositoryManager.obtainRetrofitService(UserService.class)
                .getData(json)
                .map(result -> {
                    if(result.getTotal()>0){
                        return result.getRows();
                    }else{
                        throw  new  Exception("没有查询到盘点数据！");
                    }

                });
    }
}